<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .input-box {
            margin: 10px;
            display: flex;
            align-items: center;
        }

        .input-box input {
            flex: 1;
            height: 40px;
            border: 1px solid #ccc;
            outline: none;
            padding-left: 20px;
            border-radius: 5px;
        }

        .input-box span {
            text-align: center;
            color: lightseagreen;
            width: 60px;
        }

        .list {
            margin: 10px;
        }

        .list .task {
            margin: 20px 0;
            display: flex;
            justify-content: space-between;
            padding: 15px;
            background-color: rgb(227, 161, 161);
            color: white;
        }
         .list .task.active{
            background-color: lightseagreen;
        }
        .empty{
            text-align: center;
            margin: 50px 0;
            color: red;
        } 
        .nav{
            justify-content: space-around;
            display: flex;
        }
        .nav p{
            height: 40px;
            line-height:40px;
            min-width: none;
            color: white;
            padding: 0 10px;
            box-sizing: border-box;
            text-align: center;
            border-radius: 15px;
            background-color:lightseagreen ;
        }
        .nav p:nth-child(3){
            background-color: red;
        }
        .nav p span{
            padding: 5px 10px;
        }

    </style>
</head>

<body>
    <div id="app">
        <div class="input-box">
            <input type="text" placeholder="输入任务名称" v-model="inputText">
            <span @click="add">添加</span>
        </div>
        <div class="nav">
            <p>全部任务<span>({{tasklist.length}})</span></p>
            <p>已完成<span>({{adds()}})</span></p>
            <p>未完成<span>({{apps()}})</span></p>
        </div>
        <div class="list">
            <h3>任务列表</h3>
            <div :class="`task ${item.status? 'active':''}` " v-for="(item,index) in tasklist" :key="index">
                <input type="checkbox" @click="changeStatus(item)">
                <div class="study">{{item.name}}</div>
                <span class="btn" @click="del(index)">删除</span>
            </div>
            <div class="empty" v-show="tasklist == 0">任务列表是空的！请添加任务！</div>
        </div>
    </div>
</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v = new Vue({
        el: '#app',
        data: {
            inputText: '',//保存输入框中的值
            tasklist: [
                // {id:1,name:'任务名称',status:true}
            ],
            tasklists:[]
        },
        methods: {
            add() {
                if (this.inputText) {
                    var obj = { id: this.tasklist.length + 1, name: this.inputText, status: false };
                    this.tasklist.push(obj);
                    console.log(this.tasklist);
                    // 输入完之后需要清空
                    this.inputText= '';
                }
            },
            adds(){
                var count =0
                this.tasklist.map((item, index) => {
                    if(item.status == true){
                        count++
                    }
                }).join('')
                return count
            },
            apps(){
                var counts =0
                this.tasklist.map((item, index) => {
                    if(item.status == false){
                        counts++
                    }
                }).join('')
                return counts
            },
            changeStatus(item){//更改任务状态
                item.status = !item.status
            },
            del(index){
                this.tasklist.splice(index,1)
            }
        }
    })
</script>